home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char NrsId[] = "@(#)$Header: nrs.SH,v 3.2 87/06/24 18:13:44 pb Rel $";
- #endif lint
-
- /* Copyright 1986, Piete Brooks, Julian Onions & Adrian Pell
- * pb@cl.cam.ac.uk, jpo@hcig.nott.ac.uk, Adrian.R.Pell@reading.ac.uk
- *
- * This program may be copied as long as you don't remove this notice,
- * try to make any money off of it, or pretend that you wrote it.
- */
-
- #include <stdio.h>
- #include <ctype.h>
-
- /* Define one of these if needed */
- /* #undef VMS21 /* VAX VMS C 2.1 (used in nrs.h & misc) */
- #define PRIME /* PR1ME */
- /* #undef VOID /* V7 doesn't understand (void) */
-
- /* #undef index strchr
- /* #undef USE_GETHOSTNAME /* Use BSD gethostname() */
- /* #undef USE_UNAME /* Use USG uname() */
-
- /* Options .... */
- #define F_YORK /* york output format enabled */
- #define F_X25HOSTS /* /etc/x25hosts format */
- #define F_MMDF /* mmdf format enabled */
- #define F_TEXT /* text format enabled */
- #define F_SMAIL /* reading sendmail format */
- #define F_VMS /* vms format enabled */
- #define F_SENDMAIL /* UK sendmail format */
- #define F_DBM1 /* ucl dbm format */
- #define F_PRIME /* generate PRIME format .. what else ?? */
- #define F_EDTEXT /* Edinburgh text format */
-
- /* #undef MMDF_CHAN_BOTH_FORMS /* Long AND short in mmdf.chan tables ? */
-
- /* Dependant info ... */
- #ifdef PRIME
- # include <time.h>
- # define off_t Header
- # define time_t struct tm
- # define static_f
- # define universaluse(x) (char *) (x)
- # define universaldec(x) char * x;
- #ifdef UNIX
- UNIX on a PR1ME ?? If so, delete this line.
- #endif UNIX
- #else PRIME
- # include <sys/types.h>
- #endif PRIME
-
- #ifdef VMS21
- # include <stat.h> /* For time_t */
- # define exit_rc(x) (!x) /* lowest bit SET -> OK */
- # undef UNIX /* This ain't UNIX ! */
- #else VMS21
- # define noshare
- #endif VMS21
-
- #ifndef VOID
- # define VOID (void)
- #endif VOID
-
- #ifndef static_f
- # define static_f static
- #endif static_f
- #ifndef universaldec
- # define universaldec(x)
- # define universaluse(x) x
- #endif universaldec
- #ifndef exit_rc
- # define exit_rc(x) x
- #endif exit_rc
-
- #define warn0(f) warn_3(f, universaluse(0), universaluse(0), universaluse(0))
- #define warn1(f, a1) warn_3(f, universaluse(a1), universaluse(0), universaluse(0))
- #define warn2(f, a1, a2) warn_3(f, universaluse(a1), universaluse(a2), universaluse(0))
- #define warn3(f, a1, a2, a3) warn_3(f, universaluse(a1), universaluse(a2), universaluse(a3))
-
- #define fatal0(f) fatal_2(f, universaluse(0), universaluse(0))
- #define fatal1(f, a1) fatal_2(f, universaluse(a1), universaluse(0))
- #define fatal2(f, a1, a2) fatal_2(f, universaluse(a1), universaluse(a2))
-
- #define vprintf0(n, f) vprintf_3(n, f, universaluse(0), universaluse(0), universaluse(0))
- #define vprintf1(n, f, a1) vprintf_3(n, f, universaluse(a1), universaluse(0), universaluse(0))
- #define vprintf2(n, f, a1, a2) vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(0))
- #define vprintf3(n, f, a1, a2, a3) vprintf_3(n, f, universaluse(a1), universaluse(a2), universaluse(a3))
-
- # define TRUE 1
- # define FALSE 0
- # define UNSET -1 /* not yet set to anything */
- # define KEEPOPEN 01 /* keep file open */
- # define GETFNUMBER 02 /* file has a file number */
- # define SEEKFNUMBER 04 /* file number must be sought */
- # define MAXQUADS 40 /* max quads we can cope with */
- # define MOD2 "MODULE2" /* default module2 name */
- # define MOD3 "MODULE3" /* default module3 name */
- # define MOD4 "MODULE4" /* default module4 name */
- # define DERFIL_D1 "DERFIL2" /* default number 1 */
- # define DERFIL_D2 "DERFIL1" /* default number 2 */
- # define MAXNAMELEN 128 /* generally large string */
- # define MAXAR 10 /* max application relays */
- # define MAXDESC 10 /* max description lines */
- # define TAGSIZE 6 /* size of tag in atomic files */
- # define MAXTABLES 40 /* maximum atomic files in table*/
- # define MAXDOMAINS 20 /* maximium domains for mmdf */
- # define MAXLOCDOMAINS 20 /* max loc domains for york */
- # define MAGIC '$' /* magic char in comments */
- # define DCONTEXTS 10 /* Max number of domain contexts*/
-
- /* atomic files fields */
- # define DT 1 /* dte stuff */
- # define YB 2 /* Yellow book */
- # define AR 3 /* application relay */
- # define DI 4 /* description */
-
- /* long and the short of it */
- # define LONG 1 /* long name */
- # define SHORT 2 /* short name */
- # define FORWARD 3 /* map forwards */
- # define REVERSE 4 /* map reverse */
- # define MIXED 5 /* mixed case */
- # define LOWER 6 /* lower case */
- # define IGNORERELAY 7 /* ignore application relay strings --
- * e.g. in VMS still generate entry */
-
- /* Contexts that we're interested in */
- # define X29 1 /* x29 context */
- # define TS29 2
- # define NIFTP 3 /* ftp blue book context */
- # define MAIL_NIFTP 4 /* grey book mail context */
- # define MAIL_X29 5
- # define MAIL_TELEX 6
- # define JTMP 7
- # define JTMP_FILES 8
- # define JTMP_REG 9
- # define YBTS_NODE 10
- # define YBTS 11
- # define DESC 12
- # define MAXCONTEXTS (DESC+1)
-
- /* the networks */
- # define PSS 1
- # define JANET 2
- # define TELEX 3
- # define MAXSUBNETS (TELEX+1)
-
- # define max(X,Y) ((X) < (Y)? (Y) : (X))
- # define min(X,Y) ((X) > (Y)? (Y) : (X))
-
- typedef short /*int*/ small; /* V7: remove int ?? */
-
- /* structure of the Module2 file */
- typedef struct mod2 {
- int index_disp; /* index into module4 */
- int ls_disp; /* index into module2 */
- small ls; /* long/short flag */
- small length; /* length of string */
- char name[MAXNAMELEN]; /* the string */
- } Mod2;
-
- /* structure of the module3 file (unused) */
- typedef struct mod3 {
- small m3_context;
- small m3_network;
- small m3_direction;
- int l_disp;
- char m3_dte[MAXNAMELEN];
- char m3_ybts[MAXNAMELEN];
- /* char m3_desc[MAXNAMELEN]; */
- small m3_length;
- char m3_string[MAXNAMELEN];
- } Mod3;
-
- /* The quad structure */
- typedef struct Quad {
- small fnumb; /* the file number to find it in */
- int ngtwys; /* the no. of gateways (what the hell is this?) */
- int disp; /* the displacement in the file */
- small nlines; /* the number of lines in the file */
- } Quad;
-
- /* structure of the module4 file */
- typedef struct mod4 {
- small nquads; /* the number of quads */
- Quad quads[MAXQUADS]; /* the quads */
- } Mod4;
-
- /* the file header - one for each file */
- typedef struct Header {
- int H_nlines; /* no. of lines in file */
- int fnumber; /* the file number */
- long *offset; /* lines to seek values */
- } Header;
-
- typedef struct Table {
- char *T_name; /* the file name */
- small T_context; /* the context */
- small T_network; /* the network */
- small T_direction; /* the direction */
- Header hdr; /* The header for the file */
- } Table;
-
- #define DIR_FORWARDS 1
- #define DIR_REVERSE 2
- #define MAXDIRECTIONS (DIR_REVERSE+1)
-
-
- /* structure for the atomic file */
- typedef struct atomic {
- char *dte; /* The dte string */
- char *ybts; /* the yb string */
- char *desc[MAXDESC]; /* the description */
- small n_descs; /* number of desc's */
- small n_relays; /* number of ar's */
- char *ar[MAXAR]; /* the application relays */
- small context; /* what context this is in */
- small network; /* which subnet this is on */
- small direction; /* which direction this is */
- } Atomic;
-
- typedef struct domain { /* domain information (DERFIL2 only) */
- char name[MAXNAMELEN]; /* name of domain */
- char gateway[MAXNAMELEN]; /* gateway name or address */
- int n_contexts; /* number of contexts */
- int contexts[DCONTEXTS]; /* contexts */
- } Domain;
-
- typedef struct lookup { /* struct used by lookup() routines */
- char *str;
- int value;
- } Lookup;
-
- typedef struct version {
- int hours;
- int minutes;
- int day;
- int month;
- int year;
- int format;
- } Version;
-
- /* structure of the list of localdomains */
- typedef struct l_list {
- int len; /* length of the string */
- char *string; /* the string */
- } L_list;
-
- Header Module2; /* info on the module 2 file */
- Header Module3; /* info on the module 4 file */
- Header Module4; /* info on the module 4 file */
- Header Domains; /* info on the domains file */
- Version thisversion; /* the current database version */
-
- extern Table tablist[]; /* the table of files */
- extern Lookup contexts[]; /* list of contexts */
- extern Lookup netnames[]; /* list of networks */
- extern Lookup lc_netnames[]; /* list of networks in lower case */
- extern Lookup netabbrevs[]; /* network abbreviations */
- extern Lookup directions[]; /* list of directions */
- #ifdef F_YORK
- extern Lookup def_ybstring[]; /* list of default yb service names */
- extern Lookup imp_services[]; /* list of implicit yb service names */
- extern Lookup exp_services[]; /* list of explicit yb service names */
- #endif F_YORK
- #ifdef F_YORK21
- #ifndef F_YORK
- extern Lookup def_ybstring[]; /* list of default yb service names */
- #endif F_YORK
- extern Lookup exp_21services[]; /* list of explicit yb service names */
- #endif F_YORK21
- #ifdef F_VMS
- extern Lookup vms_services[]; /* list of vms context name */
- #endif F_VMS
- #ifdef F_DBM1
- #define DBSEP '\034'
-
- #define R_MAIN '#'
- #define R_ALIAS '>'
- #define R_REV '$'
- #define R_DOMAIN '@'
-
- #define DEF_MAXFTP 50
- #define DEF_LOCAL 0
- #define DEF_OLD 0
- #define DEF_DISABLED 0
- #endif F_DBM1
- #ifdef F_PRIME
- int primeformat();
- #endif F_PRIME
-
- Mod2 *getm2rec();
- Mod3 *getm3rec();
- Mod4 *getm4rec();
- Atomic *getatrec();
- Table *gettab();
- char *vlookup();
- char *lowerfy();
- FILE *getfp();
- int noformat();
-
- # ifdef F_YORK
- int yorkformat();
- #define COLON ((char) (':' | 0x80))
- # endif F_YORK
-
- # ifdef F_X25HOSTS
- int x25hostsformat();
- # endif F_X25HOSTS
-
- # ifdef F_MMDF
- int mmdfformat();
- int mmdfdomain();
- #define FLIP
- #define MULT_OUTPUT_FILES
- # endif F_MMDF
-
- # ifdef F_TEXT
- int textformat();
- # endif F_TEXT
-
- # ifdef F_VMS
- int vmsm4rec();
- int vmsformat();
- # endif F_VMS
-
- # ifdef F_EDTEXT
- int edtextm4rec();
- int edtextformat();
- int edtextdomain();
-
- #define FL_CNTX 4 /* Width of the first field (context) */
- #define FL_NET 1 /* Width of network field */
- #define FL_DOM 10 /* Width of domain name (in domain section) */
- #define FL_PREF1 18 /* Width of "shortform" prefix */
- #define FL_PREF2 22 /* Width of "longform" prefix */
-
- #define O_ED_MASK 0x0007
- #define O_ED_LONG 0x0004
- #define O_ED_SHORT 0x0002
- #define O_ED_SIMPLE 0x0001
- #define O_ED_DEFAULT O_ED_SHORT
- # endif F_EDTEXT
-
- # ifdef F_SMAIL
- int smailformat();
- # endif F_SMAIL
-
- # ifdef F_SENDMAIL
- int sendmailformat();
- int sendmaildomain();
- #define FLIP
- #define MULT_OUTPUT_FILES
- # endif F_SENDMAIL
-
- # ifdef F_YORK21
- int york21m4rec();
- # ifndef COLON
- #define COLON ((char) (':' | 0x80))
- # endif COLON
- extern L_list localdomains[]; /* local domains */
- # endif F_YORK21
-
- #ifdef F_DBM1
- int dbm1m4rec();
- int dbm1format();
- int dbm1domain();
- #endif F_DBM1
-
- # ifdef MULT_OUTPUT_FILES
- # define LOCAL 01
- # define USED 02
-
- typedef struct file_list {
- char *dname; /* domain name - short form */
- char *ldname; /* domain name - long form */
- char *fname; /* the file associated with above */
- small net; /* the associated network if any */
- small flags; /* various flags - see above */
- } File_list;
-
- extern File_list fil_list[]; /* list of mmdf domains & channels */
- extern char *relay_host; /* relay host to janet */
- #endif MULT_OUTPUT_FILES
-
- extern char *calloc();
- extern char *strdup();
- extern char *strcpy();
- extern char *strncpy();
- extern char *strcat();
- extern char *malloc();
- extern char *index();
- extern char *getfpath();
- extern int (*outputm4rec)(); /* output a complete m4 record */
- extern int (*outputformat)();
- extern int (*outputdomain)(); /* output a domain record */
-
- extern char *invo_name; /* the prog name (argv[0]) */
- extern int trip2fnumb[MAXCONTEXTS][MAXSUBNETS][MAXDIRECTIONS];
- /* Map triple to file number */
- extern int max_fnumb; /* the max file number we've got*/
- extern int ignore_relay; /* ignore application relay strings --
- * e.g. in VMS still generate entry */
- extern int verbose; /* verbosity level */
- extern int forwrev; /* forward/reverse lookup */
- extern int longshort; /* is long or short form used ? */
- extern int mixlow; /* mixed/lower case */
- extern int usederfil; /* use derived file */
- extern int options; /* output specific options */
- extern char nullstring[]; /* The null string (no value) */
- extern char *M2file; /* the Module2 file name */
- extern char *M3file; /* the module3 file name */
- extern char *M4file; /* the module4 file name */
- extern char *Derfile; /* the derived file name */
- extern char *DOMfile; /* the domain file name */
- extern char *janetgateway; /* gateway to janet */
- extern char *pssgateway; /* gateway to pss */
- extern char *directory; /* the unix directory for files */
- extern char *stripoff; /* strip off this prefix in output */
- extern char *hostname; /* the name of this host */
- extern char *commentfile; /* the file with comments in */
-